package org.tooyoung.fourone.chat;

import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.widget.EditText;

import com.hyphenate.chat.EMClient;
import com.hyphenate.exceptions.HyphenateException;

import org.tooyoung.fourone.R;

public class AddActivity extends AppCompatActivity {

    private EditText txtName;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_add);

        txtName = (EditText) findViewById(R.id.add_name);
    }

    public void btnAdd(View view) {
        String name = txtName.getText().toString().trim();
        new AddThread(name).start();
    }

    private class AddThread extends Thread{

        private String name;

        public AddThread(String name) {
            this.name = name;
        }

        @Override
        public void run() {
            try {
                EMClient.getInstance().contactManager().addContact(name , "请求添加您为好友");
            } catch (HyphenateException e) {
                e.printStackTrace();
            }
        }
    }
}
